package ccy.ccykills.command;

import ccy.ccykills.config.CcyConfig;
import ccy.ccykills.config.KillGift;
import ccy.ccykills.playerdata.PlayerData;
import ccy.ccylibrary.command.CommandExecution;
import ccy.ccylibrary.plugin.annotation.command;
import ccy.ccylibrary.utils.Method;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.List;


@command(
        name = "ckill"
)
public class PlayerCommand implements CommandExecutor {
    public PlayerCommand() {
    }

    public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
        if (command.getName().equalsIgnoreCase("ckill")) {
            if (commandSender instanceof Player) {
                Player player = (Player)commandSender;
                if (strings.length >= 2 && strings[0].equals("gift")) {
                    if (CcyConfig.config.killGiftMap.containsKey(strings[1])) {
                        KillGift killGift = CcyConfig.config.killGiftMap.get(strings[1]);
                        PlayerData playerData = new PlayerData(player);
                        List<String> gift = playerData.getGift();
                        if (gift.contains(strings[1])) {
                            Method.sendmessage(player, "&c领取失败，你已经领取过了!");
                        } else if (playerData.getNum() >= killGift.getValue()) {
                            Method.sendmessage(player, "&a领取成功!");
                            gift.add(strings[1]);
                            playerData.setGift(gift);
                            CommandExecution.Command(player, killGift.getList());
                        } else {
                            Method.sendmessage(player, "&c领取失败，杀敌数未达标!");
                        }

                        return false;
                    }

                    Method.sendmessage(player, "&c该礼包不存在!");
                    return false;
                }
            }

            Method.sendmessage(commandSender, "/ckill gift <礼包名> - 达到一定的积分领取礼包");
        }

        return false;
    }
}